//
//  UIView+Common.m
//  gamebox_qpp
//
//  Created by 赵隆杰 on 2022/9/9.
//

#import "UIView+Common.h"
#import <BlocksKit/BlocksKit.h>


@implementation UIView (Common)

- (void)addTapBlock:(TapAction)tapAction {
    [self setTapAction:tapAction];
    if (![self gestureRecognizers]) {
        self.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)];
        [self addGestureRecognizer:tapGes];
    }
}

- (void)setTapAction:(TapAction)tapAction {
    if (tapAction) [self bk_associateValue:tapAction withKey:@"tapAction"];
}

- (TapAction)tapAction {
    return [self bk_associatedValueForKey:@"tapAction"];
}

- (void)tap {
    if (self.tapAction) {
        self.tapAction(self);
    }
}

@end
